package com.qyhl.party.party.supplement;

import com.qyhl.party.common.PartyUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.party.PartyLoginBean;
import com.qyhl.webtv.commonlib.entity.party.PartyZoneBean;

import java.util.List;

public class PartySupplementModel implements PartySupplementContract.PartySupplementModel {
    private PartySupplementPresenter mPresenter;

    public PartySupplementModel(PartySupplementPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getCode(String phone) {
        EasyHttp.post(PartyUrl.PARTY_GET_MESSAGE)
                .params("phone", phone)
                .execute(new SimpleCallBack<Boolean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setCode(e.getMsg());
                    }

                    @Override
                    public void onSuccess(Boolean b) {
                        mPresenter.setCode("短信验证码发送成功,5分钟内有效！");
                    }
                });
    }

    @Override
    public void getZoneList() {
        EasyHttp.post(PartyUrl.PARTY_STREET_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<PartyZoneBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setZoneError("获取区域失败！");
                    }

                    @Override
                    public void onSuccess(List<PartyZoneBean> beanList) {
                        mPresenter.setZoneList(beanList);
                    }
                });
    }

    @Override
    public void register(String phone, String name, String code, String card, int zoneId, int depId, String polFace, int isWork) {
        EasyHttp.post(PartyUrl.PARTY_USER_REGISTER)
                .params("phone", phone)
                .params("code", code)
                .params("card", card)
                .params("zoneId", zoneId + "")
                .params("depId", depId + "")
                .params("polFace", polFace)
                .params("isWork", isWork + "")
                .params("name", name)
                .execute(new SimpleCallBack<PartyLoginBean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.registerError(e.getMsg());
                    }

                    @Override
                    public void onSuccess(PartyLoginBean bean) {
                        mPresenter.registerSuccess(bean);
                    }
                });

    }

    @Override
    public void change(String phone, String name, String token, String card, int zoneId, int depId, String polFace, int isWork) {
        EasyHttp.post(PartyUrl.PARTY_USER_MODIFY)
                .headers("Authorization", token)
                .params("phone", phone)
                .params("card", card)
                .params("zoneId", zoneId + "")
                .params("depId", depId + "")
                .params("polFace", polFace)
                .params("isWork", isWork + "")
                .params("name", name)
                .execute(new SimpleCallBack<Boolean>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.registerError(e.getMsg());
                    }

                    @Override
                    public void onSuccess(Boolean bean) {
                        mPresenter.registerSuccess(null);
                    }
                });
    }
}
